/**
* @Description: WoShop商城
* @Author: 梧桐
* @Copyright: 武汉一一零七科技有限公司©版权所有
* @Link: www.s1107.com
* @Contact: QQ:2487937004
*/
<template>
	<view class="index_class">
		<view class="rele-areat">
			<!--  app 端状态栏站位 -->

			<view class="u-flex u-row-between input-text" @click="openSort">
				<view>类型</view>
				<!-- <input type="text" v-model="chooseType.label" disabled="true" placeholder="请选择举报类型"> -->
				<picker @change="bindPickerChange" :value="index" :range="array" mode="selector">
				  <view class="uni-input"> {{array[index]}}  <i class="iconfont icon_e60c"></i></view>
				</picker>
			</view>
			<!-- <mpvue-picker ref="mpvuePicker" :mode="mode" :pickerValueDefault="pickerValueDefault" @onChange="onChange"
			 @onConfirm="onConfirm" @onCancel="onCancel" :pickerValueArray="getNavList">
			</mpvue-picker> -->

   
			<view class="input-text">
				<textarea v-model="textValue" name="" id="" cols="30" rows="10" placeholder="想要说的话"></textarea>
				<view class="text-number">{{textValue.length}}/800</view>
			</view>

			<view class="addfile">
				<view class="grace-add-file">
					<view class="grace-add-btn" @tap="addImg" v-if="btnImg">
						<view>+</view>
						<view>添加照片</view>
					</view>
					<view class="garce-items" v-for="(item, index) in imgLists" :key="index">
						<image :src="item" mode="widthFix" :data-imgurl="item" @tap="showImgs"></image>
						<view class="grace-close" @tap="removeImg" :id="'grace-items-img-'+index"></view>
					</view>
				</view>
			</view>


			<view class="person-button" style="margin:0;background-color:#fff;padding-top:40upx">
				<!-- @click="getnav('/pagesB/personalSon/RefundDatecopy')" -->
				<button type="warn" class="btn" @click="getaddthorder" style="border-radius: 15px;">提交</button>

			</view>
		</view>
	</view>
</template>


<script>
import mpvuePicker from '@/components/mpvue-picker/mpvuePicker'

var maxNum = 9,
		_self;
	export default {
		components: {
			mpvuePicker
		},
		data() {
			return {
				pickerValueDefault: [0],
				chooseType: {},
				order_id: '',
				imgLists: [],
				btnImg: true,
				textValue: '',
				index: 0,
				array: ['举报主播'],
				type: '',
				sortNum: '',
				sortArr: [],
				shop_id: '',
				typeValue: ''
			}
		},

		onLoad(option) {
		  console.log(option,"sadasdasdasd")
       _self=this
      this.shop_id = option.shop_id;
		  const sortArr = [
        {
          'key' : 1,
          'value' : '举报主播'
        },
        {
          'key' : 2,
          'value':'举报客服'
        },
      ]
		  this.$set(this,'sortArr',sortArr)
		},
		computed: {
		    getNavList(val) {
		        return this.sortArr.map(res => ({
		            label: res.value,
		            value: res.value
		        }))
		    }
		},
		methods: {
			openSort() {
				this.$refs.mpvuePicker.show();
			},
			onConfirm(e) {
				this.chooseType = e
			},
			onChange(e) {
				this.chooseType = e
			},
			onCancel(e) {
				console.log(e);
			},
	
			bindPickerChange: function(e) {
				console.log("选择器",e)
				this.index = e.target.value;
				this.type = this.array[this.index];
			},
			addImg: function() {
				var num = maxNum - _self.imgLists.length;
				if (num < 1) {
					return false;
				}
				uni.chooseImage({
					count: num,
					sizeType: ['compressed'],
					success: function(res) {
						console.log(res,"添加照片")
						_self.imgLists = _self.imgLists.concat(res.tempFilePaths);
						if (_self.imgLists.length >= maxNum) {
							_self.btnImg = false;
						}
						uni.hideLoading();

					}
				});
			},
			removeImg: function(e) {
				var index = e.currentTarget.id.replace('grace-items-img-', '');
				_self.imgLists.splice(index, 1);
				_self.imgLists = _self.imgLists;
				if (_self.imgLists.length < maxNum) {
					_self.btnImg = true;
				}
			},
			showImgs: function(e) {
				var currentImg = e.currentTarget.dataset.imgurl;
				uni.previewImage({
					urls: this.imgLists,
					current: currentImg
				})
			},



			/**
			 * 图片上传
			 */
			getuploadspic() {
				if (this.imgLists.length == 0) {
					this.$toast('请先上传举报凭证')
					return false
				}
				return new Promise(resolve => {
					this.$http.getuploadspic(this.imgLists, '/api/find/uploadspic').then(res => {
						if (res.status == 200) {
							resolve(res.images)
						}
					})
				})
			},
			/**
			 *提交审核
			 */
			async getaddthorder() {
				console.log(this.shop_id,":√√√")
				// if (this.chooseType.label == '' || this.chooseType.label == undefined) {
				// 	this.$toast('请先上传举报凭证')
				// 	return false
				// }
				// if (this.textValue == '') {
				// 	this.$toast('请输入投诉内容')
				// 	return false
				// }
				// this.$loading('正在上传中...')
				let str = this.getuploadspic()
				let data = {
					type: this.type,
					tips: this.textValue,
					pic: '',
					shop_id: this.shop_id,
				}
             
				this.$http.getLiveReport(data).then(res => {
					console.log(res,"666666666")
					if (res.status == 200) {
						this.$toast(res.mess)
						setTimeout(() => {
							this.getback()
						}, 1000)
					}else{
						this.$toast(res.mess)
					}
				})
				      console.log(this.type,"举报类型",this.shop_id)
			},

       

		}
	}
</script>

<style>

</style>
